package com.woniu.user.controller;


import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.user.pojo.Feedback;
import com.woniu.user.pojo.User;
import com.woniu.user.service.IFeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 用户反馈表 前端控制器
 * </p>
 *
 * @author LiFangyu
 * @since 2023-02-15
 */
@Api(tags = "用户反馈管理")
@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    private IFeedbackService feedbackService;

    @ApiOperation("根据id查询反馈信息")
    @GetMapping("/{id}")
    public Result<Feedback> queryById(@PathVariable Long id){
        Feedback feedback = feedbackService.getById(id);
        return Result.ok(feedback);
    }

    @ApiOperation("搜索+分页")
    @PostMapping("/list/search/{currentPage}/{pageSize}")
    public Result<PageResult<Feedback>> querySearch(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            String userName){
        PageResult<Feedback> pageResult = feedbackService.querySearch(currentPage, pageSize, userName);
        return Result.ok(pageResult);
    }

    @ApiOperation("新增或修改反馈")
    @PostMapping("/saveOrUpdate")
    public Result<Feedback> querySave(@RequestBody Feedback feedback){
        boolean save = feedbackService.saveOrUpdate(feedback);
        return Result.ok();
    }


    @ApiOperation("根据id删除反馈")
    @DeleteMapping("/{id}")
    public Result<Feedback> queryDeleteFeedback(@PathVariable String id){
        boolean b = feedbackService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("反馈id查看用户信息")
    @GetMapping("/user/{id}")
    public Result<User> queryUser(@PathVariable Integer id){
        User user = feedbackService.queryUser(id);
        return Result.ok(user);
    }


    @ApiOperation("修改反馈状态")
    @PutMapping("/{id}")
    public Result queryStatus(@PathVariable Long id){

        boolean b = feedbackService.queryStatus(id);

        return Result.ok();
    }

}
